package org.genntii.warehousesystem.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.genntii.warehousesystem.common.Result;
import org.genntii.warehousesystem.domain.dto.WarehouseDTO;
import org.genntii.warehousesystem.domain.vo.WarehouseVO;
import org.genntii.warehousesystem.service.WarehouseService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "仓库接口")
@RestController
@RequestMapping("/warehouse")
public class WarehouseController {

    @Resource
    private WarehouseService warehouseService;

    @Operation(summary = "添加仓库")
    @PostMapping("/v1/add")
    public Result add(@RequestBody WarehouseDTO dto){
        warehouseService.add(dto);
        return Result.success();
    }

    @Operation(summary = "禁用仓库",description = "将仓库设为禁用")
    @Parameter(name = "id",description = "仓库id",required = true,in = ParameterIn.QUERY)
    @PostMapping("/v1/del")
    public Result del(@RequestParam("id") int id){
        warehouseService.del(id);
        return Result.success();
    }

    @Operation(summary = "启用仓库")
    @Parameter(name = "id",description = "仓库id",required = true,in = ParameterIn.QUERY)
    @PostMapping("/v1/enable")
    public Result enable(@RequestParam("id")int id){
        warehouseService.enable(id);
        return Result.success();
    }

    @Operation(summary = "更新仓库信息")
    @Parameter(name = "id",description = "仓库id",required = true,in = ParameterIn.QUERY)
    @PostMapping("/v1/update")
    public Result update(@RequestParam("id")int id,@RequestBody WarehouseDTO dto){
        warehouseService.update(id,dto);
        return Result.success();
    }

    @Operation(summary = "分页查找启用仓库")
    @Parameter(name = "page",description = "页码",required = true,in = ParameterIn.QUERY)
    @GetMapping("/v1/findEnable")
    public Result<List<WarehouseVO>> findEnable(@RequestParam("page") int page){
        return Result.success(warehouseService.findAllEnabled(page));
    }

    @Operation(summary = "分页查找禁用仓库")
    @Parameter(name = "page",description = "页码",required = true,in = ParameterIn.QUERY)
    @GetMapping("/v1/findUnable")
    public Result<List<WarehouseVO>> findUnable(@RequestParam("page") int page){
        return Result.success(warehouseService.findAllUnable(page));
    }

    @Operation(summary = "查找相同省份仓库")
    @Parameter(name = "cityId",description = "城市id",required = true,in = ParameterIn.QUERY)
    @GetMapping("/findSameCity")
    public Result<List<WarehouseVO>> findSameCity(@RequestParam("cityId") int cityId){
        return Result.success(warehouseService.findSameCity(cityId));
    }

}
